<?php

namespace App\Http\Controllers\View\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Facades\Services\Admin\WechatDoctorService;
use App\Facades\Utils\ValidateParameter;

class WechatDoctorController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        // dd(WechatDoctorService::getWechatDoctors()->toArray());

        return view('pages.admin.wechat_doctor.list',[
            'wechatDoctors' => WechatDoctorService::getWechatDoctors()
        ]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function detail(Request $request)
    {
        $rules = [
            'id' => 'required|exists:wechat_doctors,id'
        ];

        ValidateParameter::validate($request,$rules);

        $data = $request->all();

        // dd(WechatDoctorService::getWechatDoctor($data)->toArray());
        // 
        $wechatDoctor = WechatDoctorService::getWechatDoctor($data);

        return view('pages.admin.wechat_doctor.detail',[
            'wechatDoctor' => $wechatDoctor,
            'qrcode' => WechatDoctorService::getQRCode($wechatDoctor)
        ]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request)
    {
        $rules = [
            'id' => 'required|exists:wechat_doctors,id'
        ];

        ValidateParameter::validate($request,$rules);

        $data = $request->all();

        // dd(WechatDoctorService::getWechatDoctor($data)->toArray());

        // dd(WechatDoctorService::getDoctorType());

        $wechatDoctor = WechatDoctorService::getWechatDoctor($data);

        return view('pages.admin.wechat_doctor.update',[
            'wechatDoctor' => $wechatDoctor,
            'doctorTypes' => WechatDoctorService::getDoctorType(),
            'qrcode' => WechatDoctorService::getQRCode($wechatDoctor)
        ]);
    }


    public function create(Request $request){

        $rules = [
            'id' => 'required|exists:wechat_doctors,id'
        ];

        ValidateParameter::validate($request,$rules);

        $data = $request->all();

        // dd(WechatDoctorService::getWechatDoctor($data)->toArray());

        // dd(WechatDoctorService::getDoctorType());

        $wechatDoctor = WechatDoctorService::getWechatDoctor($data);

        return view('pages.admin.wechat_doctor.create',[
            'wechatDoctor' => $wechatDoctor,
            'doctorTypes' => WechatDoctorService::getDoctorType(),

        ]);
    }

    public function userList(Request $request){
        $rules = [
            'openid' => 'required|exists:wechat_doctors,openid'
        ];

        ValidateParameter::validate($request,$rules);

        $data = $request->all();

        return view('pages.admin.wechat_doctor.user_list',[
            'wechatUsers' => WechatDoctorService::getTheUsers($data)
        ]);
    }
}
